package org.mozhu.mboot.admin.system.privilege.entity;

import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.Parameter;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.mozhu.mboot.core.data.entity.Activatable;
import org.mozhu.mboot.core.data.entity.BaseEntity;
import org.mozhu.mboot.core.data.hibernate.type.CollectionToStringType;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Set;

@TypeDef(name = "SetToStringUserType", typeClass = CollectionToStringType.class, parameters = {@Parameter(name = "separator", value = ","),
        @Parameter(name = "collectionType", value = "java.util.HashSet"), @Parameter(name = "elementType", value = "java.lang.Long")})
@Entity
@Table(name = "sys_role")
@Data
@EqualsAndHashCode(callSuper = true)
public class Role extends BaseEntity implements Activatable {

    private static final long serialVersionUID = 2950707131281980995L;

    /**
     * 前端显示名称
     */
    private String name;

    /**
     * 系统中验证时使用的角色标识
     */
    private String code;

    /**
     * 详细描述
     */
    private String description;

    /**
     * 是否是默认权限
     */
    @Column(name = "default_role")
    private Boolean defaultRole = Boolean.FALSE;

    @Type(type = "SetToStringUserType")
    @Column(name = "permission_ids")
    private Set<Long> permissionIds;

    /**
     * 激活(TRUE)，冻结(FALSE)
     */
    private Boolean activated = Boolean.TRUE;

    public boolean isAvailable() {
        return getActivated();
    }
}
